package yedean.bean;

import com.yedean.factory.BeanFactory;
import com.yedean.factory.BeanFactoryAware;
import com.yedean.factory.context.ApplicationContext;
import com.yedean.factory.context.ApplicationContextAware;
import com.yedean.factory.support.DisposableBean;
import com.yedean.factory.support.InitializingBean;
import lombok.Data;
import lombok.ToString;

import java.lang.reflect.InvocationTargetException;

/**
 * UserService
 *
 * @author yedean
 * @date 2022/6/27
 */
@ToString
@Data
public class UserService implements InitializingBean, DisposableBean, ApplicationContextAware, BeanFactoryAware {
    private String uId;
    
    private String location;
    
    private String company;
    
    private UserDao userDao;
    
    private ApplicationContext context;
    
    private BeanFactory beanFactory;
    

    public UserService(String uId, UserDao userDao) {
        this.uId = uId;
        this.userDao = userDao;
    }

    public UserService() {
    }

    public String queryUserInfo() {
        return userDao.queryUserName(uId)+", 公司："+company+", 地点"+location;
    }


    @Override
    public void destroy() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        System.out.println("执行：UserService.destroy");
    }
        
    @Override
    public void afterPropertySet() {
        System.out.println("执行：UserService.afterPropertiesSet");
    }
    
    public void initMethod(){
        System.out.println("执行userService的初始化方法");
    }
    
    public void destroyMethod(){
        System.out.println("执行userService的销毁方法");
    }

    @Override
    public void setApplicationContext(ApplicationContext context) {
        this.context=context;
        System.out.println("成功感知应用上下文并加载到bean中!");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        this.beanFactory=beanFactory;
        System.out.println("成功感知到bean工厂并加载到bean!");
    }
}
